<template>
  <div class="bigScreenGoods">
    <scroll class="bigScreenGoods" :on-infinite="onInfinite">
      <div
        class="order-item"
        v-for="(it, ind) in list"
        v-if="list && Array.isArray(list) && list.length"
        :key="ind"
      >
        <div class="tableNo">
          <span> 座位号：{{ it.tableNo }} </span>
          <span class="create-name">创建人:{{ it.creatorName }}</span>
        </div>
        <div class="date">
          {{ new Date(it.addTime).Format("yyyy/MM/dd hh:mm:ss") }}
        </div>
        <div class="note">备注:{{ it.remark ? it.remark : "---" }}</div>
        <div class="goods-wrap" v-if="Array.isArray(it.items)">
          <div class="goods" v-for="(ite, ind) in it.items" :key="ind">
            <div class="left-cont">
              {{ ite.productName
              }}<span v-if="Array.isArray(ite.specs) && ite.specs.length"
                >({{ ite.specs.join(",") }})</span
              ><b>[{{ ite.code }}]</b>
            </div>
            <div class="right-cont">
              <span class="btn" v-if="ite.makeType == 'makeIng'"
                >制作中...</span
              >
              <span
                class="btn suc"
                v-if="ite.makeType == 'deliveryIng'"
                @click.stop="sendOk(ite, 'single')"
                >完成</span
              >
            </div>
          </div>
        </div>
        <div class="all-ok">
          <span class="submit" @click.stop="sendOk(it, 'all')">全部完成</span>
        </div>
      </div>
      <!-- <div class="no-data">暂无数据</div> -->
      <!-- </div> -->
      <div v-if="!haveMore" slot="infinite" class="text-center">
        暂无更多数据
      </div>
    </scroll>
    <div class="all-item-ok" @click.stop="allok">
      <span>全部</br>完成</span>
    </div>
    <div class="mask" v-if="dialogBtn">
            <div class="alert-tab">
                <div class="main-tit">
                  注意！
                </div>
                <div class="tit">
                    是否完成所有订单？
                </div>
                <div class="btn">
                    <span @click.stop="dialogBtn=false">取消</span>
                    <span class="sure" @click.stop="doAllok">确定</span>
                </div>
            </div>
        </div>
  </div>
</template>
<script>
export default {
  name: "bigScreenGoods",
  props: ["storeId"],
  data() {
    return {
      dialogBtn: false,
      list: [],
      pageSize: 20,
      haveMore: true,
      curPage: 0,
    };
  },
  methods: {
    allok() {
      this.dialogBtn = true;
    },
    doAllok() {
      this.$http({
        url: window.API_BASE_URL + "v1/admin/deal/all",
        method: "POST",
        data: {
          storeId: this.storeId,
        },
      }).then((res) => {
        this.dialogBtn = false;
        this.curPage = 0;
        this.list = [];
        this.getData();
      }).catch(err=>{
        this.dialogBtn = false;
      });
    },
    //
    sendOk(item, type) {
      let itemIds = [];
      if (type == "all") {
        if (item.items && Array.isArray(item.items)) {
          item.items.forEach((it) => {
            itemIds.push(it.id);
          });
        }
      } else {
        itemIds = [item.id];
      }
      this.$http({
        url: "/boss/update/type",
        method: "POST",
        data: {
          itemIds: [...new Set(itemIds)],
          makeOrderId: item.masterId,
          type: "deliveryFinished",
        },
      }).then((res) => {
        this.getData();
      });
    },
    //
    onInfinite(done) {
      this.curPage++;
      this.$http({
        url: window.API_BASE_URL + "v1/admin/boss/get/by/type",
        method: "POST",
        data: {
          storeId: this.storeId,
          size: this.pageSize,
          page: this.curPage,
          finished: false,
        },
      })
        .then((res) => {
          if (res && res.data && res.data.content) {
            res.data.content.forEach((it) => {
              it.masterId = it.id;
              if (it.items && Array.isArray(it.items)) {
                it.items.forEach((ite) => {
                  ite.masterId = it.id;
                });
              }
            });
            this.list = Array.isArray(res.data.content)
              ? this.list.concat(res.data.content)
              : [];
            done();
            return;
          } else {
            this.haveMore = false;
            this.curPage--;
            done();
            return;
          }
        })
        .catch(() => {
          done();
        });
      //
    },
    getData() {
      this.list = [];
      this.$http({
        // url: window.API_BASE_URL + "v1/pos/orders/get/by/type",
        url: window.API_BASE_URL + "v1/admin/boss/get/by/type",
        method: "POST",
        data: {
          storeId: this.storeId,
          size: this.pageSize,
          page: 0,
          finished: false,
        },
      }).then((res) => {
        if (res && res.data && res.data.content) {
          res.data.content.forEach((it) => {
            it.masterId = it.id;
            if (it.items && Array.isArray(it.items)) {
              it.items.forEach((ite) => {
                ite.masterId = it.id;
              });
            }
          });
          this.list = Array.isArray(res.data.content)
            ? this.list.concat(res.data.content)
            : [];
          if (
            res.data.totalElements <= this.pageSize ||
            !res.data.content.length
          ) {
            this.haveMore = false;
            return;
          }
        } else {
          this.haveMore = false;
          return;
        }
      });
    },
  },
  mounted() {
    this.getData();
  },
};
</script>
<style lang="scss" scoped>
.bigScreenGoods {
  width: 100%;
  /* height: 100%; */
  top: 45px;
  overflow: hidden;
  overflow-y: auto;
  background-color: #fff;
  box-sizing: border-box;
  .create-name {
    font-size: 0.28rem;
    color: #666;
  }
  .order-item {
    padding: 0.24rem;
    box-sizing: border-box;
    border-bottom: 1px solid #ddd;
    .tableNo {
      font-size: 0.32rem;
      font-weight: bold;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .date {
      padding: 0.12rem 0;
      font-size: 0.26rem;
      color: #999;
    }
    .note {
      color: #999;
      font-size: 0.26rem;
    }
    .goods-wrap {
      display: flex;
      flex-wrap: wrap;
      .goods {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 0.459rem;
        &:last-child {
          margin: 0;
        }
        .left-cont {
          width: 80%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .right-cont {
          width: 20%;
          .btn {
            display: flex;
            align-items: center;
            justify-content: center;
            height: 0.5rem;
            box-sizing: border-box;
            background-color: #ddd;
            border-radius: 0.25rem;
            font-size: 0.24rem;
            padding: 0 0.12rem;
            color: #999;
            &.suc {
              color: #fff;
              background-color: #d66767;
            }
          }
        }
      }
    }
    .all-ok {
      display: flex;
      justify-content: center;
      align-items: center;
      padding-top: 0.5rem;
      .submit {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 59%;
        height: 0.59rem;
        border-radius: 0.25rem;
        background-color: #d66767;
        font-size: 0.24rem;
        color: #fff;
      }
    }
  }
}
.no-data {
  font-size: 0.24rem;
  text-align: center;
  padding: 0.24rem 0;
  color: #999;
}
.all-item-ok {
  position: fixed;
  bottom: 1rem;
  right: 0.5rem;
  width: 1rem;
  height: 1rem;
  border-radius: 0.5rem;
  background-color: #ed8626;
  color: #fff;
  z-index: 999999;
  font-size: 0.24rem;
  span {
    position: absolute;
    top: 50%;
    left: 50%;
    line-height: 0.24rem;
    transform: translate(-50%, -50%);
  }
}
.mask,
.standard-mask {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.3);
  z-index: 100;
  .alert-tab,
  .standard-wrap {
    width: 80%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 5px;
    padding: 10px;
    .main-tit {
      padding-bottom: 0.5rem;
      text-align: center;
      font-weight: bold;
    }
    .tit {
      text-align: center;
      padding-bottom: 0.5rem;
    }
    .next-item {
      width: 100%;
      font-size: 0;
      margin-bottom: 15px;
      text-align: center;
      span {
        display: inline-block;
        font-size: 14px;
        vertical-align: middle;
        &.tit-span {
          padding-right: 10px;
        }
        &.tit-cont {
          width: 65%;
        }
        input {
          display: inline-block;
          width: 59%;
          border-bottom: 1px solid #ddd;
          border-radius: 0;
          text-align: center;
        }
        select {
          width: 59%;
        }
      }
    }
    .btn {
      display: flex;
      justify-content: space-around;
      padding-top: 15px;
      padding: 0 20px;
      span {
        display: inline-block;
        width: 30%;
        height: 30px;
        text-align: center;
        color: #fff;
        line-height: 30px;
        background: #ccc;
        border-radius: 3px;
        &.sure {
          background: rgb(44, 155, 247);
        }
      }
    }
  }
  .standard-wrap {
    padding: 0;
    li {
      padding: 5px 0;
      text-align: center;
      border-bottom: 1px solid #ddd;
    }
  }
}
</style>
